package com.mdlib.helper.ui.adapter;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ljlib.help.R;
import com.mdlib.helper.model.entity.OrderEntity;

import java.util.List;

/**
 * 作者：HQY on 16/11/28 14:41
 * 邮箱：hqy_xz@126.com
 */

public class RushMyOrderAdapter extends BaseQuickAdapter<OrderEntity> {

    public RushMyOrderAdapter(List<OrderEntity> data) {
        super(R.layout.item_rush_my_order, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, OrderEntity order) {

        baseViewHolder.setText(R.id.tv_rush_order_goods_name, order.getRemark());
        baseViewHolder.setText(R.id.tv_rush_order_service_money, "￥" + order.getServiceMoney());
        baseViewHolder.setText(R.id.tv_rush_order_address_two, order.getGetAddr());

        TextView mTvOrderType = baseViewHolder.getView(R.id.tv_rush_order_distance);
        TextView mTvOrderSubmit = baseViewHolder.getView(R.id.tv_rush_order_step);

        int status = order.getOrderStatus();
        baseViewHolder.addOnClickListener(R.id.tv_rush_order_step);

        TextView mTvOrderTypes = baseViewHolder.getView(R.id.tv_rush_order_address_one);
        int busType = order.getBusType();
        if (busType == 1) {
            Glide.with(mContext)
                    .load(R.drawable.iv_details_agecy)
                    .into((ImageView) baseViewHolder.getView(R.id.iv_rush_order_type));
            baseViewHolder.setText(R.id.tv_rush_order_type, mContext.getResources().getString(R.string.send_home_agency));


            Drawable agencys = mContext.getResources().getDrawable(R.drawable.vicinity_order_class);
            agencys.setBounds(0, 0, agencys.getMinimumWidth(), agencys.getMinimumHeight());
            mTvOrderTypes.setCompoundDrawables(agencys, null, null, null);
            mTvOrderTypes.setText(order.getHandleType());
        } else if (busType == 2) {
            Glide.with(mContext)
                    .load(R.drawable.iv_details_minnetonka)
                    .into((ImageView) baseViewHolder.getView(R.id.iv_rush_order_type));
            baseViewHolder.setText(R.id.tv_rush_order_type, mContext.getResources().getString(R.string.send_home_minnetonka));

            Drawable minn = mContext.getResources().getDrawable(R.drawable.vicinity_order_shop);
            minn.setBounds(0, 0, minn.getMinimumWidth(), minn.getMinimumHeight());
            mTvOrderTypes.setCompoundDrawables(minn, null, null, null);
            mTvOrderTypes.setText(order.getPostAddr());
        } else if (busType == 3) {
            Glide.with(mContext)
                    .load(R.drawable.iv_details_take)
                    .into((ImageView) baseViewHolder.getView(R.id.iv_rush_order_type));
            baseViewHolder.setText(R.id.tv_rush_order_type, mContext.getResources().getString(R.string.send_home_take));

            Drawable takes = mContext.getResources().getDrawable(R.mipmap.vicinity_order_take);
            takes.setBounds(0, 0, takes.getMinimumWidth(), takes.getMinimumHeight());
            mTvOrderTypes.setCompoundDrawables(takes, null, null, null);
            mTvOrderTypes.setText(order.getPostAddr());
        }

        if (status == 1) {
            mTvOrderType.setText(mContext.getResources().getString(R.string.generic_order_type_one));
            mTvOrderSubmit.setVisibility(View.GONE);
        } else if (status == 2) {
            mTvOrderType.setText(mContext.getResources().getString(R.string.generic_run_order_type_two));
            mTvOrderSubmit.setVisibility(View.GONE);

        } else if (status == 3) {
            if (order.getOfflinePayGoods().equals("false")) {
                mTvOrderType.setText(mContext.getResources().getString(R.string.generic_run_order_type_three));
            } else {
                mTvOrderType.setText("线下支付");
            }
            mTvOrderSubmit.setVisibility(View.VISIBLE);
            mTvOrderSubmit.setText("确认购买");

        } else if (status == 4) {
            mTvOrderType.setText(mContext.getResources().getString(R.string.generic_run_order_type_four));
            mTvOrderSubmit.setVisibility(View.VISIBLE);
            mTvOrderSubmit.setText("确认送达");

        } else if (status == 5) {
            mTvOrderType.setText(mContext.getResources().getString(R.string.generic_run_order_type_five));
            mTvOrderSubmit.setVisibility(View.GONE);

        } else if (status == 6) {
            mTvOrderType.setText(mContext.getResources().getString(R.string.generic_order_type_six));
            mTvOrderType.setTextColor(mContext.getResources().getColor(R.color.generic_view_bg));
            mTvOrderSubmit.setVisibility(View.GONE);
        } else if (status == 7) {
            mTvOrderType.setText(mContext.getResources().getString(R.string.generic_order_type_seven));
            mTvOrderType.setTextColor(mContext.getResources().getColor(R.color.generic_view_bg));
            mTvOrderSubmit.setVisibility(View.GONE);

        } else if (status == 8) {
            mTvOrderType.setText(mContext.getResources().getString(R.string.generic_order_type_eight));
            mTvOrderSubmit.setVisibility(View.GONE);

        } else if (status == 9) {
            mTvOrderType.setText(mContext.getResources().getString(R.string.generic_order_type_night));

        }

    }
}
